<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <div class="tabs">
      <el-tabs stretch type="border-card" v-model="activeName">
        <el-tab-pane name="account">
          <!-- 插槽 -->
          <template #label>
            <div class="label">
              <el-icon><UserFilled /></el-icon>
              <span class="text">帐号登录</span>
            </div>
          </template>
          <PaneAccount ref="accountRef"></PaneAccount>
        </el-tab-pane>
        <el-tab-pane name="phone">
          <!-- 插槽 -->
          <template #label>
            <div class="label">
              <el-icon><Iphone /></el-icon>
              <span class="text">手机登录</span>
            </div>
          </template>
          <PanePhone></PanePhone>
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="controls">
      <el-checkbox v-model="isRemPwd" label="记住密码" size="large" />
      <el-link type="primary">忘记密码</el-link>
    </div>

    <el-button
      class="login-btn"
      type="primary"
      size="large"
      @click="handleLoginBtnClick"
      >立即登录</el-button
    >
  </div>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import PaneAccount from './pane-account.vue'
import PanePhone from './pane-phone.vue'
import { localCache } from '@/utils/cache'
// ref<boolean> 函数 泛型  泛型推导
// 是否记住密码
const isRemPwd = ref<boolean>(localCache.getCache('isRemPwd') ?? false)
watch(isRemPwd, (newValue) => {
  console.log(newValue)

  localCache.setCache('isRemPwd', newValue)
})

// activeName
const activeName = ref('account')
// 组件实例的类型 any相当于js代码啦
// const accountRef = ref<any>()
// 拿实例 固定写法
const accountRef = ref<InstanceType<typeof PaneAccount>>()
// 立即登录
function handleLoginBtnClick() {
  if (activeName.value === 'account') {
    // 拿到子组件实例 ，执行子组件的方法
    // ?可选链  ?可选参数
    accountRef.value?.loginAction(isRemPwd.value)
    // 两种方式传给子组件 或者传给父组件
    // if (isRemPwd.value) {
    //   console.log('记住账号密码')
    // }
  } else {
    console.log('手机登录')
  }
}
</script>
<style lang="less" scoped>
.login-panel {
  width: 330px;
  margin-bottom: 150px;

  .title {
    text-align: center;
    margin-bottom: 15px;
  }

  .label {
    display: flex;
    align-items: center;
    justify-content: center;

    .text {
      margin-left: 5px;
    }
  }

  .controls {
    margin-top: 12px;
    display: flex;

    justify-content: space-between;
  }

  .login-btn {
    margin-top: 10px;
    width: 100%;
    // --el-button-size: 50px;
  }
  // 直接覆盖那个类也行 变量
}
</style>
